/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package frontera;

import Control.CrudEmpleado;
import java.awt.Color;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;

/**
 *
 * @author felipe
 */
public class PanelEmpleado extends javax.swing.JPanel {

        public static DefaultTableModel dtmempleados;
        
    
    public PanelEmpleado() {
        initComponents();
        basedeDatos();
        inicializar();
    }

    
    public void inicializar(){
        CrearEmpleadoBoton.setVisible(true);
        
        dtmempleados = new DefaultTableModel(new Object[][]{}, new String[]{"ID", "Nombre", "Contraseña", "Rol" }){};
        
        
        
        TablaEmpleados.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        TableColumnModel tsm = TablaEmpleados.getColumnModel();
       DiseñoColumna DC = new DiseñoColumna(Color.orange);
       
       TablaEmpleados.setModel(dtmempleados);
       
       for(Entidad.Empleado p: CrudEmpleado.bringAll()){
           System.out.println(p.getID());
           dtmempleados.addRow(new Object[]{p.getID(), p.getNombre(), p.getContraseña(), p.getRol()});
           
       }
       
       TablaEmpleados.setDefaultRenderer(Object.class, new FormatoTabla());
       tsm.getColumn(0).setCellRenderer(DC);
    }
    private void basedeDatos(){
    CrudEmpleado.crearEmpleado(409823, "Jake Example", "Servicio al Cliente", "666");

    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        CrearEmpleadoBoton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        TablaEmpleados = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();

        setPreferredSize(new java.awt.Dimension(1000, 869));

        CrearEmpleadoBoton.setText("Crear Empleado");
        CrearEmpleadoBoton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CrearEmpleadoBotonActionPerformed(evt);
            }
        });

        TablaEmpleados.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(TablaEmpleados);

        jLabel1.setText("Lista de Empleados");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 980, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(CrearEmpleadoBoton)
                            .addComponent(jLabel1))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jLabel1)
                .addGap(28, 28, 28)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 653, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(CrearEmpleadoBoton)
                .addGap(106, 106, 106))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void CrearEmpleadoBotonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CrearEmpleadoBotonActionPerformed
        CrearEmpleado nuevoEmpleado = new CrearEmpleado();
        nuevoEmpleado.setVisible(true);
    }//GEN-LAST:event_CrearEmpleadoBotonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton CrearEmpleadoBoton;
    private javax.swing.JTable TablaEmpleados;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
